<?php
if(!$model)
	$model = SlideShow::model()->findByPk ($modelId);
$flag_normal_exit_file = false;
$normalDir = $model->getImageDir().DIRECTORY_SEPARATOR.'_normal'.$model->image;
if(file_exists($normalDir))
	$flag_normal_exit_file = true;

if($flag_normal_exit_file == false)
	$css = '.img-thumb{margin-top: 106px !important;}.img-large{width:350px !important;}#frame-upload-image-category{margin-top: -29px!important;}';
else
	$css = '.img-thumb{margin-top: 170px !important;}.img-large{width:350px !important;margin-top: 64px !important;}';
echo CHtml::css($css);
?>
<table class="items">
    <thead>
        <tr>
            <th class="no"><?php echo Yii::t('BackEnd', 'No.')?></th>
			<?php if($flag_normal_exit_file==true){?>
				<th class="large"><?php echo Yii::t('BackEnd', 'Original image')?></th>
			<?php } ?>
            <th class="large"><?php echo Yii::t('BackEnd', 'Large')?></th>
            <th class="medium"><?php echo Yii::t('BackEnd', 'Small')?></th>
        </tr>
    </thead>
    <tbody>
        <?php
		if($flag_normal_exit_file==true)
			$imageSourceUrl = 'http://'.$_SERVER['SERVER_NAME'].CHtml::encode($images['normal']).'?v='.time();
		else
			$imageSourceUrl = 'http://'.$_SERVER['SERVER_NAME'].CHtml::encode($images['large']).'?v='.time();
		?>

		<tr class="<?php echo ($index%2)?'odd':'even'?>">
			<td class="fixed"><?php echo $index+1?></td>
			<?php if($flag_normal_exit_file==true){?>
				<td>
					<img alt="normal-<?php echo $item->name;?>" class="img-normal" id="img-normal-<?php echo $images['id']; ?>" src="<?php echo $images['normal'].'?v='.time();?>"/>
					<a id="delete-this" rel="<?php echo $modelId;?>" rev="<?php echo $modelName;?>" title="<?php echo Yii::t('BackEnd','Delte this');?>">
						<img id="del-img" src="<?php echo Yii::app()->request->baseUrl; ?>/css/admin/images/icons/delete-img.png"/>
					</a>
				</td>
			<?php } ?>
            <td>
                <a href="<?php echo Yii::app()->createUrl('site/cropImage', array('id'=> $images['id'], 'type'=>'large', 'src'=>$imageSourceUrl, 'modelName'=>$modelName, 'modelId'=>$modelId));?>">
                    <img alt="large-<?php echo $item->name;?>" class="img-large" id="img-large-<?php echo $images['id']; ?>" src="<?php echo $images['large'].'?v='.time();?>" title="<?php echo Yii::t('BackEnd','Click to edit');?>"/>
                </a>
            </td>
            <td>
                <a href="<?php echo Yii::app()->createUrl('site/cropImage', array('id'=> $images['id'], 'type'=>'thumb','src'=>$imageSourceUrl, 'modelName'=>$modelName, 'modelId'=>$modelId));?>">
                    <img style=" margin-top: 27px;" alt="thumb-<?php echo $item->name;?>" class="img-thumb" id="img-thumb-<?php echo $images['id']; ?>" src="<?php echo $images['thumb'].'?v='.time();?>"  title="<?php echo Yii::t('BackEnd','Click to edit');?>">
                </a>
            </td>
        </tr>
    </tbody>
</table>
<!--Upload image-->
<div id="frame-upload-image-category">
	<h2>Đổi ảnh khác</h2>
	<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'upload-avatar-form',
		'action'=> $this->createUrl('slideShow/uploadImage'),
		'enableAjaxValidation'=>false,
		'htmlOptions' => array('enctype'=>'multipart/form-data'),
	));
		echo CHtml::openTag('input',array('type'=>'hidden','value'=>$model->id,'name'=>'hiddenId'));
		echo CHtml::openTag('em').Yii::t('BackEnd','Warning image format and size').CHtml::closeTag('em');
		echo CHtml::openTag('p');
			echo CHtml::openTag('label').Yii::t('BackEnd','From mycomputer').CHtml::closeTag('label');
			echo $form->fileField($model,'image',array('size'=>57,'maxlength'=>255, 'name'=>'image'));
			echo $form->error($model,'image');
		echo CHtml::closeTag('p');
		echo CHtml::openTag('p');
			echo CHtml::openTag('label').Yii::t('BackEnd','From internet').CHtml::closeTag('label');
			echo CHtml::openTag('input',array('name'=>'remote_url','value'=>$avartar,'id'=>'formItn'));
		echo CHtml::closeTag('p');
		echo CHtml::openTag('span');
			echo CHtml::submitButton(Yii::t('BackEnd','Upload'),array('id'=>'save'));
			echo CHtml::openTag('a',array('id'=>'reset','onclick'=>'javascript:parent.$.colorbox.close();')).Yii::t('BackEnd','Cancel').CHtml::closeTag('a');
		echo CHtml::closeTag('span');
		$this->endWidget();
	echo CHtml::openTag('span').CHtml::closeTag('span');
	?>
</div>